package sng.modules.view.components.city.logic.unit
{
	import as3isolib.geom.IsoMath;
	import as3isolib.geom.Pt;
	
	import com.greensock.plugins.FilterPlugin;
	
	import core.interfaces.IDispose;
	
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.GradientType;
	import flash.display.MovieClip;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.geom.Matrix;
	import flash.geom.Point;
	import flash.text.TextField;
	import flash.utils.getDefinitionByName;
	
	import mx.collections.ArrayCollection;
	import mx.controls.Alert;
	
	import org.casalib.util.ArrayUtil;
	
	import sng.data.info.BuildingInfo;
	import sng.data.info.GlobalInfo;
	import sng.modules.model.vo.BuildingVO;
	import sng.modules.model.vo.UserBuildingVO;
	import sng.modules.view.components.city.logic.City;
	import sng.modules.view.components.city.logic.CityView;
	import sng.modules.view.components.city.logic.attachment.BuildingTipManager;
	import sng.modules.view.components.city.logic.event.TileEvent;
	import sng.modules.view.components.city.logic.movement.Directions;
	import sng.modules.view.components.city.state.BuildGatherState;
	import sng.modules.view.components.city.state.BuildNewState;
	import sng.modules.view.components.city.state.BuildNormalState;
	import sng.modules.view.components.city.state.CityNewState;
	import sng.modules.view.components.city.state.EnumBuildState;
	import sng.modules.view.components.city.state.IBuildState;
	import sng.modules.view.components.city.state.ICityState;
	import sng.modules.view.components.city.strategy.BusinessStrategy;
	import sng.modules.view.components.city.strategy.CapitalAssertsStrategy;
	import sng.modules.view.components.city.strategy.CommunityStrategy;
	import sng.modules.view.components.city.strategy.DecorationStrategy;
	import sng.modules.view.components.city.strategy.ExpandStrategy;
	import sng.modules.view.components.city.strategy.FarmingStrategy;
	import sng.modules.view.components.city.strategy.HouseStrategy;
	import sng.modules.view.components.city.strategy.LandmarkStrategy;
	import sng.modules.view.components.city.strategy.RoadStrategy;
	import sng.modules.view.components.city.strategy.StorageStrategy;
	import sng.modules.view.components.city.strategy.Strategy;
	import sng.utils.AttachmentTextUpUtil;
	import sng.utils.BuildingUtil;
	import sng.utils.FilterUtil;
	import sng.utils.IsoUtil;
	
	/**
	 * 
	 * 建筑物基类
	 * 
	 */	
	public class BaseBuilding extends Tile implements IDispose
	{
		//TODO 建筑的唯一id，后续需要服务器传递该id，目前模拟实现
		public static var bId:uint;
		
		private var _view:CityView;
		private var ab:HouseStrategy;
		private var ac:BusinessStrategy;
		private var af:FarmingStrategy;
		private var ar:RoadStrategy;
		private var aSt:StorageStrategy;
		private var aco:CommunityStrategy;
		private var lan:LandmarkStrategy;
		private var dec:DecorationStrategy;
		private var expand:ExpandStrategy;
		public var progress:AttachmentProgreass;
		private var ca:CapitalAssertsStrategy;
		//public var isIdle:Boolean = false;
		public var itempstate:uint;//保存当前的正式状态，从临时状态转变回时使用
		
		public function get view():CityView
		{
			return _view;
			
		}
		
		public function set view(value:CityView):void
		{
			_view = value;
		}
		
		public var uVO:UserBuildingVO;
		public var vo:BuildingVO;
		
		public var currentDirection:String = Directions.N;
		public var skin:SwfSheet;
		public var currentStrategy:Strategy;
		public var currentStep:uint;//如果建筑是在建造、升级过程中，处于第几步，0表示不在建筑状态, 默认为0
		
		private var _isDragStart:Boolean=false;
		public function get isDragStart():Boolean
		{
			return _isDragStart;
		}

		public function set isDragStart(value:Boolean):void
		{
			_isDragStart = value;
			currentStrategy.setFuncRun(!_isDragStart);//开始拖动就停止记时，停止拖动就开始计时
				
				
		}

//当前建筑是否被选择为开始移动
		/**
		 *保存当前的状态，如果从当前状态转到转向状态，移动状态，空闲状态后，再转回来时就使用此状态 
		 */		
		//public var tempstate:uint;
				
		public function BaseBuilding(_vo:UserBuildingVO, _view:CityView,_city:City,strategy:Strategy=null)
		{
			
			city=_city;
			
			uVO = _vo;
			
			vo = BuildingInfo.getBuildingVOFromTemplateId(_vo.templateId);
			view = _view;
			skin = new SwfSheet(vo.buildingSwfUrl);

			
			//根据配置文件获取策略类
			var classname:String="sng.modules.view.components.city.strategy."+vo.stragegy;
			var classReference:Class = Class(getDefinitionByName(classname));
			//
			var instance:Object = new classReference(this,vo,_vo );
			
			currentStrategy=instance as Strategy;
		//建筑初始状态由策略类的构造函数来完成
			
			
			currentDirection = uVO.direction;
			currentStep = uVO.buildStep==0?vo.createStep:uVO.buildStep;
			
			sprites.unshift(skin);
			currentStrategy.idleBuildingStrategy();//空闲判断
				
			
			skin.addEventListener(TileEvent.SKIN_LOAD_COMPLETE, skinLoadComplete);
			
			id = bId.toString();
			
			//添加格子背景 royjin 20110715
			//if(this.vo.buildingTypeId==BuildingUtil.DECORATION_TYPE)
			//{
				this.CreateGroundSkin();
			//}
			//创建Bonus文字特效
			this.CreateBonusText();
		}
		
		
		//建筑鼠标悬浮状态
		//改为GroundScene中checkMouseOver方法调用 eason 20110713
		public function doMouseOver():void
		{
			currentState.doMouseOver(this,city.currentState.toString());
		}
		
		//建筑鼠标悬浮移除处理
		//改为GroundScene中checkMouseOver方法调用 eason 20110713
		public function doMouseOut():void
		{
			
			currentState.doMouseOut(this,city.currentState.toString());
		}
		
		//改为GroundScene中checkMouseOver方法调用 eason 20110713
		public function doMouseClick():void
		{
			if(isProgress) return;
			city.currentBuilding=this;
			city.currentState.Execute();
		}
		
		
		/**
		 *
		 */		
		protected var _city:City;
		
		/**
		 *获取当前建筑所在的城市  
		 * 
		 * 
		 */		
		public function get city():City
		{
			return _city;
		}
		
		/**
		 *设置当前建筑所在的城市   
		 * @param value
		 * 
		 */		
		public function set city(value:City):void
		{
			_city = value;
		}
		
		/**
		 *当前城市的状态 
		 */		
		protected var _cityState:ICityState;
		
		protected var _currentState:IBuildState;
		private var tempState:IBuildState;
		
		/**
		 * 
		 * @param buildState
		 * 改变建筑当前状态
		 * 
		 */		
		public function setBuildState(buildState:IBuildState):void
		{			
			if (currentState!=null)//currentState.getiStateType()!=EnumBuildState.MOVE_STATE && 
			{
				if (currentState.getiStateType()!=EnumBuildState.IDLE_STATE )
					itempstate=currentState.getiStateType();
			}
			else//新建城市状态，建筑还没有初始状态
			{
				if (buildState.getiStateType()!=EnumBuildState.IDLE_STATE)
					itempstate=buildState.getiStateType();
				else
					itempstate=this.uVO.nextState;//默认为空闲状态时
			}
			tempState = currentState;
			currentState=buildState;
			uVO.currentState = buildState.getiStateType();
		}
		/**
		 *当前建筑的状态 
		 */
		public function get currentState():IBuildState
		{
			return _currentState;
		}
		
		/**
		 * @private
		 */
		public function set currentState(value:IBuildState):void
		{
			_currentState = value;
		}
		
		/**
		 * 创建建筑
		 * 
		 */		
//		public function create():void
//		{
//			//			DragManager.getInstance().drag(this, cityView);
//		}
		
//		public function CreateComplete():void
//		{
//			var list:ArrayCollection = city.hudVo.userbuildinglist;
//			var length:uint = list.length;
//			if((currentStep>=vo.createStep && vo.createStep>1) || tempState!=null)
//			{
//				var userBvo:UserBuildingVO;
//				var state:IBuildState = tempState==null?new BuildNormalState():tempState;
//				setBuildState(state);
//				currentStrategy.moveBuildingStrategy();
//				for(var i:uint=0;i<length;i++)
//				{
//					userBvo = list.getItemAt(i) as UserBuildingVO;
//					if(userBvo.buildingid == uVO.buildingid)
//					{
//						userBvo.y = Math.floor(this.y/City.GRID_CELLSIZE);
//						userBvo.x = Math.floor(this.x/City.GRID_CELLSIZE);
//						userBvo.buildStep = uVO.buildStep;
//						userBvo.currentState = uVO.currentState;
//						break;
//					}
//				}
//			}
//			else
//			{
//				setBuildState(new BuildNewState());
//				currentStrategy.createBuildingStrategy();
//				uVO.y = Math.floor(this.y/City.GRID_CELLSIZE);
//				uVO.x = Math.floor(this.x/City.GRID_CELLSIZE);
//				list.addItem(uVO);
//			}
//			//设置城市的可建区域数据
//			city.setCityBuildData();
//		}
		
		/**
		 * 
		 * 拆除建筑
		 * 
		 */		
//		public function destroy():void
//		{
//			currentStrategy.deleteBuildingStrategy();
//			view.removeTile(this);
//			
//			var list:ArrayCollection = city.hudVo.userbuildinglist;
//			var length:uint = list.length;
//			var userBvo:UserBuildingVO;
//			for(var i:uint=0;i<length;i++)
//			{
//				userBvo = list.getItemAt(i) as UserBuildingVO;
//				if(userBvo.buildingid == uVO.buildingid)
//				{
//					list.removeItemAt(i);
//					break;
//				}
//			}
////			city.setCityBuildData();
////			cityView.updateBuildingInfoGridArr(this,this.uVO.buildingid);
////			dispose();
//		}
		
		/**
		 * 播种操作
		 * 
		 */		
		//TODO 后续移动位置
		public function seed():void
		{
			if(vo.buildingid == BuildingInfo.BUILD_FARM)
			{
				//点击农田，播种完成
				skin.getMC().gotoAndStop("升级1");
				currentStrategy.supplyGoodsBuildingStrategy();
			}else{
				//未点击农田，取消城市的播种状态
				city.setCityState(new CityNewState(city));
			}
		}
		
		/**
		 * 移动建筑
		 * 
		 */		
		public function move():void
		{
			
		}
		
		/**
		 * 隐藏sprites中的所有元素
		 * eason 20110713 
		 */
		private function hide():void
		{
			for each(var s:Sprite in this.sprites)
			{
				s.alpha=0;
			}
		}
		
		/**
		 * 显示sprites中的所有元素
		 * eason 20110713 
		 */
		private function show():void
		{
			for each(var s:Sprite in this.sprites)
			{
				s.alpha=1;
			}		
		}
		
		public function BeginMove():void
		{
			isDragStart=true;
			IsoUtil.updateAllMapDataInfo(this,false);
//			trace(City.buildingIdArray.dump())
			hide();
			cityView.groundScene.closeMouseOverEffect();//禁用鼠标悬浮提示 eason 20110714
			cityView.groundScene.closeTileClick();//禁用建筑点击 eason 20110714
			DragManager.getInstance().drag(vo, cityView, uVO);
		}
		
		
		public function EndMove():Boolean
		{
			isDragStart=false;
			this.x = this.uVO.x*City.GRID_CELLSIZE;
			this.y = this.uVO.y*City.GRID_CELLSIZE;
			
			//显示 eason20110714
			show();
			//打开鼠标悬浮提示 eason 20110714
			cityView.groundScene.openMouseOverEffect();
			//打开建筑点击 eason 20110714
			cityView.groundScene.openTileClick();
			IsoUtil.updateAllMapDataInfo(this,true);
			
			return true;
		}
		
		/**
		 * 建筑转向
		 * 
		 */		
		public function rotate():void
		{
			if(currentStep<vo.createStep) return;
			currentDirection = Directions.getNextDirection(currentDirection);
			skin.getMC().gotoAndStop(currentDirection);
		}
		
		/**
		 * 查看细节，弹出查看窗口
		 * 
		 */		
		public function viewDetail():void
		{
			
		}
		
		/**
		 * 升级建筑
		 * 
		 */		
		public function upgrade():void
		{
			if(isProgress) return;
			if(vo.buildingTypeId == BuildingUtil.ROAD_TYPE) return;
			var text:AttachmentTextUp;
			var pt:Pt;
			var point:Point;
			try
			{
			var mc:MovieClip = skin.getMC();
			if(currentStep<vo.createStep)
			{
				//增加能量控制
				if (GlobalInfo.mainvo.energy>0)
				{
					GlobalInfo.mainvo.energy-=1;
					AttachmentTextUpUtil.addText(this,"-1能量",AttachmentTextUp.WHITE);
				}
				else
				{
					Alert.show("对不起,能量不够！");
					return;
				}
				mc.gotoAndStop("建造");
				mc.baseBuild_mc.gotoAndPlay("f"+currentStep.toString());
				currentStep++;
				uVO.buildStep++;
				setProgress(true);
			}
			else if(currentStep==vo.createStep)
			{
				//增加能量控制
				if (GlobalInfo.mainvo.energy>0)
				{
					GlobalInfo.mainvo.energy-=1;
					AttachmentTextUpUtil.addText(this,"-1能量",AttachmentTextUp.WHITE);
				}
				else
				{
					Alert.show("对不起,能量不够！");
					return;
				}
				mc.baseBuild_mc.gotoAndPlay("f"+currentStep.toString());
				setProgress(true, upgradeOver);
			}
			}
			catch(error:Error)
			{
				trace(error);
			}
			function upgradeOver():void
			{
				isProgress = false;
				removeTip();
				mc.gotoAndStop(currentDirection);
				//setBuildState(new BuildNormalState);
				currentStrategy.addBuildingStrategy();
				//currentStrategy.addBuildingStrategy();
				uVO.buildStep = 0;
				uVO.currentState = 1;
			}
		}
		
		/**
		 * 建筑的皮肤载入成功
		 * @param event
		 * 
		 */		
		protected function skinLoadComplete(event:Event):void
		{
//			if (_drag)
//				DragManager.getInstance().drag(this, cityView);		
//			else
//			{
				currentState.setSkin(this);
				this.invalidateSprites();
//			}
		}
		
		/**
		 * 居民类建筑的人口加上显示动画
		 * @param num
		 * 
		 */		
		//TODO 后续考虑放到House类中 考虑放在cityview的attachmentScene中统一管理
		//更改到city中的attachmentContainer eason 20110719
		public function addPopulationAnimation(num:uint):void
		{
			var attachment:AttachmentTextUp = new AttachmentTextUp("+"+num.toString()+"人口",AttachmentTextUp.WHITE);		
			view.city.doTextTipAnimation(attachment,view.mouseX,view.mouseY);
//			this.sprites.push(attachment);
//			invalidateSprites();
			
		}
		
		/**
		 * 居民类建筑的金币提示出现
		 * @param num
		 * 
		 */		
		public function addCoinTip():void
		{
			var coinTip:AttachmentCoinTip = new AttachmentCoinTip();
			coinTip.mouseEnabled = false;
			coinTip.mouseChildren = false;
			coinTip.y = -vo.height;
			
			this.sprites.push(coinTip);
			invalidateSprites();
			
		}
		
		/**
		 * 商业类建筑的货物提示出现
		 * @param num
		 * 
		 */		
		public function addGoodsTip():void
		{
			var goods:AttachmentGoodsTip = new AttachmentGoodsTip();
			goods.mouseEnabled = false;
			goods.mouseChildren = false;
			goods.y = -vo.height;
			
			this.sprites.push(goods);
			invalidateSprites();
			
		}
		
		private var isProgress:Boolean = false;
		/**
		 * 进度条动画表现
		 * @param num
		 * 
		 */		
		public function setProgress(noDrop:Boolean=false, callFunction:Function=null):void
		{
//			view.attachmentScene.addDrop(new OperateBar(view, "", [removeProgress]), this.uVO.x, this.uVO.y);
			isProgress = true;
//			return;
			
			progress = new AttachmentProgreass();
			if(!noDrop)
				progress.nameText.text = "收取...";
			
			this.sprites.push(progress);
			invalidateSprites();
			if(noDrop)
			{
				if(callFunction!=null)
					progress.addEventListener("progressOver", callFunction, false, 0, true);
				else
					progress.addEventListener("progressOver", removeProgress, false, 0, true);
				return;
			}
			
			
			if(vo.dropExp!=0)
				progress.addEventListener("progressOver", dropExp, false, 0, true);
			
			if(vo.dropGoods!=0)
				progress.addEventListener("progressOver", dropGoods, false, 0, true);
			
			if(vo.dropCoin!=0)
				progress.addEventListener("progressOver", dropCoin, false, 0, true);
		}
		
		/**
		 * 移除进度条
		 */		
		public function removeProgress(e:Event = null):void
		{
			isProgress = false;
			removeTip();
		}
		
		/**
		 * 金币掉落动画表现
		 * @param num
		 * 
		 */		
		public function dropCoin(e:Event = null):void
		{
			isProgress = false;
			removeTip();
			cityView.attachmentScene.addDrop(new DropAttachment(view, "coin",this), this.uVO.x, this.uVO.y);
			currentStrategy.gatherProcessLater();
		}
		/**
		 * 经验掉落动画表现
		 * @param num
		 * 
		 */		
		public function dropExp(e:Event = null):void
		{
			isProgress = false;
			removeTip();
			cityView.attachmentScene.addDrop(new DropAttachment(view, "exp",this), this.uVO.x, this.uVO.y);
		}
		protected function dropGoods(event:Event = null):void
		{
			isProgress = false;
			removeTip();
			cityView.attachmentScene.addDrop(new DropAttachment(view, "goods",this), this.uVO.x, this.uVO.y);
		}
		
		/**
		 * 移除建筑的tip
		 * 
		 */		
		public function removeTip():void
		{
			while(sprites.length>1)
			{
				var mc:MovieClip = sprites.pop() as MovieClip;
				if(mc!=null)
				{
					mc.stop();
					mc = null;
				}				
			}
			invalidateSprites();

//			if(sprites.length>1)
//			{
//				var mc:MovieClip = sprites.pop() as MovieClip;
//				if(mc!=null)
//				{
//					mc.stop();
//					mc = null;
//				}
//				invalidateSprites();				
//			}
		}
		
		public function set isIdle(blIdle:Boolean):void
		{
			if (uVO.isIdle!=blIdle)
			{
				uVO.isIdle=blIdle;
				currentStrategy.idleBuildingStrategy();
			}
		}
		/**
		 * 住宅商业类的空闲状态
		 * 
		 */		
		public function setIdleUI():void
		{
			var icon:IdleIcon = new IdleIcon();
			icon.x = 30;
			icon.y = -40;
			this.sprites.push(icon);
			invalidateSprites();
		}
		
		/**
		 * 移除住宅商业类的空闲状态
		 * 
		 */	
		public function setBusyUI():void
		{
			removeTip();
		}
		
		override public function dispose():void
		{
			currentStrategy.deleteBuildingStrategy();
			view.groundScene.removeTile(this);
			
			var list:ArrayCollection = city.hudVo.userbuildinglist;
			var length:uint = list.length;
			var userBvo:UserBuildingVO;
			for(var i:uint=0;i<length;i++)
			{
				userBvo = list.getItemAt(i) as UserBuildingVO;
				if(userBvo.buildingid == uVO.buildingid)
				{
					list.removeItemAt(i);
					break;
				}
			}
		//			city.setCityBuildData();
		//			cityView.updateBuildingInfoGridArr(this,this.uVO.buildingid);
		//			dispose();
		}
		
		/**
		 * 是否是道路 royjin 20110711
		 * 
		 */
		public function IsRoad():Boolean
		{
			var res:Boolean = false;
			if(vo.buildingTypeId==BuildingUtil.ROAD_TYPE)
			{
				res = true;
			}
			return res;
		}
		
		//占地背景格子 royjin 20110715
		public var groundSkin:Sprite;
		//装饰类建筑影响范围显示 royjin 20110715
		public function ShowGroundSkin():void
		{
			if(groundSkin.parent==null)
			{
				this.sprites.unshift(groundSkin);
				this.invalidateSkins();
			}
		}
		//装饰类建筑影响范围隐藏 royjin 20110715
		public function HideGroundSkin():void
		{
			if(groundSkin.parent!=null)
			{
				org.casalib.util.ArrayUtil.removeItem(this.sprites,groundSkin);
				this.invalidateSkins();
			}
		}
		//创建一个格子背景
		private function CreateGroundSkin():void
		{
			groundSkin = new Sprite();
			var i:int;
			var j:int;
			var cols:int = this.vo.cols+6;
			var rows:int = this.vo.rows+6;
			var tempPt:Point;
			var tempPt2:Point;
			var gradientBoxMatrix:Matrix = new Matrix();	
			
			groundSkin.graphics.lineStyle(1);

			for(i=2;i<cols-1;i++)
			{
				tempPt = this.view.isoToLocal(new Pt(0,i*City.GRID_CELLSIZE));
				tempPt2 = this.view.isoToLocal(new Pt(rows*City.GRID_CELLSIZE,i*City.GRID_CELLSIZE));
				
				gradientBoxMatrix.createGradientBox(tempPt2.x-tempPt.x,1,0,tempPt.x); 
				groundSkin.graphics.lineGradientStyle(GradientType.LINEAR,[0x009900,0x009900,0x009900],[0,1,0],[0,150,255],gradientBoxMatrix);
				
				groundSkin.graphics.moveTo(tempPt.x,tempPt.y);
				groundSkin.graphics.lineTo(tempPt2.x,tempPt2.y);
			}
			for(j=2;j<rows-1;j++)
			{
				tempPt = this.view.isoToLocal(new Pt(j*City.GRID_CELLSIZE,0))
				tempPt2 = this.view.isoToLocal(new Pt(j*City.GRID_CELLSIZE,cols*City.GRID_CELLSIZE))
					
				gradientBoxMatrix.createGradientBox(tempPt.x-tempPt2.x,1,0,tempPt2.x); 
				groundSkin.graphics.lineGradientStyle(GradientType.LINEAR,[0x009900,0x009900,0x009900],[0,1,0],[0,150,255],gradientBoxMatrix);
				
				groundSkin.graphics.moveTo(tempPt.x,tempPt.y);
				groundSkin.graphics.lineTo(tempPt2.x,tempPt2.y);
			}
			
			//装饰类建筑特殊处理
			if(this.vo.buildingTypeId==BuildingUtil.DECORATION_TYPE)
			{
				groundSkin.graphics.lineStyle(1,0x009900);
				for(i=0;i<=cols;i+=cols)
				{
					tempPt = this.view.isoToLocal(new Pt(0,i*City.GRID_CELLSIZE));
					tempPt2 = this.view.isoToLocal(new Pt(rows*City.GRID_CELLSIZE,i*City.GRID_CELLSIZE));
					groundSkin.graphics.moveTo(tempPt.x,tempPt.y);
					groundSkin.graphics.lineTo(tempPt2.x,tempPt2.y);
				}
				for(j=0;j<=rows;j+=rows)
				{
					tempPt = this.view.isoToLocal(new Pt(j*City.GRID_CELLSIZE,0))
					tempPt2 = this.view.isoToLocal(new Pt(j*City.GRID_CELLSIZE,cols*City.GRID_CELLSIZE))
					groundSkin.graphics.moveTo(tempPt.x,tempPt.y);
					groundSkin.graphics.lineTo(tempPt2.x,tempPt2.y);
				}

			}
			
			//计算偏移
			var tempP1:Point = this.view.isoToLocal(new Pt(0,0));
			var tempP2:Point = this.view.isoToLocal(new Pt((3+this.vo.cols)*City.GRID_CELLSIZE,(3+this.vo.rows)*City.GRID_CELLSIZE));
			var offP:Point = new Point(tempP1.x-tempP2.x,tempP1.y-tempP2.y);
			
			groundSkin.x-=tempP1.x;
			groundSkin.y-=tempP1.y;
			
			groundSkin.x+=offP.x;
			groundSkin.y+=offP.y;
			
		}
		//Bonus文字特效 royjin 20110718
		private var bonusText:SwfSheet;
		private function CreateBonusText():void
		{
			bonusText = new SwfSheet("assets/flash/bonusfont.swf",1);
		}
		public function ShowBonusText(vl:int):void
		{
			if(bonusText!=null)
			{
				var numTxt:String = (int(this.uVO.totalBonusRate)+vl).toString();
				numTxt =  "Bonus +"+numTxt+"%";
				TextField(bonusText.mc.getChildByName("txBonus")).text = numTxt;
				var ss:Object = TextField(bonusText.mc.getChildByName("txBonus"));
				this.sprites.push(bonusText);
				this.invalidateSkins();
			}
		}
		public function HideBonusText():void
		{
			ArrayUtil.removeItem(this.sprites,bonusText);
			this.invalidateSkins();
		}
	}
}